package ee.serge.util.bootstrap;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.UListElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Hyperlink;

import ee.serge.client.Move;
import ee.serge.util.URLData;

public class BTabPanel extends ComplexPanel {

   public static final String TABS = "tabs";
   private List<Element> listElements;
   private UListElement list;
   private int selected = -1;

   public BTabPanel() {
      this(TABS);
   }
   
   public BTabPanel(String style) {
      listElements = new ArrayList<Element>();
      list = Document.get().createULElement();
      list.addClassName(style);
      setElement(list);
   }

   public int add(String tabName, URLData data) {
      Element li = Document.get().createLIElement().cast();
      list.appendChild(li);
      Hyperlink hyperlink = new Hyperlink(tabName, data.getHref());
      listElements.add(li);
      super.add(hyperlink, li);
      return listElements.size() - 1;
   }
   
   public void setSelected(int index) {
      listElements.get(index).setClassName("active");
      if (selected != -1 && selected != index) listElements.get(selected).setClassName("");
      selected = index;
   }

}
